package com.enjoyor.health.HGPT.web.rest;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.enjoyor.health.HGPT.core.dto.TestQuestionResultDto;
import com.enjoyor.health.HGPT.core.entity.SelftestContent;
import com.enjoyor.health.HGPT.service.BizConversationService;
import com.enjoyor.health.HGPT.service.BizSelfTestService;
import com.enjoyor.health.HGPT.web.CodeEnum;
import com.enjoyor.health.HGPT.web.RetResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Zhu Min
 * @date 2023/10/20 11:31
 */
@Api(value = "自测", tags = {"自测"})
@Slf4j
@RestController
public class SelfTestController {

    @Autowired
    private BizSelfTestService bizSelfTestService;
    /**
     * 发送自测题介绍
     */
    @RequestMapping(value = "/aiHealthReport/selftestIntroduction", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getTestIntroduction(String selftestId){
        List<SelftestContent> selftestContentList = bizSelfTestService.getSelftestContent(selftestId);
        JSONObject result = new JSONObject();
        if (selftestContentList != null && selftestContentList.size() >0){
            SelftestContent selftestContent = selftestContentList.get(0);
            result.put("name", selftestContent.getTitle());
            result.put("type", selftestContent.getTitleEn());
            result.put("according", selftestContent.getBaseInfo());
            result.put("duration", selftestContent.getIntroDuration());
            result.put("questionNumber", selftestContent.getIntroNumberQuestion());
            result.put("peopleNumber", selftestContent.getIntroNumberPeople());
            result.put("introduction", selftestContent.getIntroText());
        }
        return new RetResult().of(CodeEnum.SUCCESS).setResult(result);
    }

    /**
     *  发送自测题题目
     */
    @RequestMapping(value = "/aiHealthReport/selftestQuestions", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getTestQuestions(String selftestId, String openId){
        return new RetResult().of(CodeEnum.SUCCESS).setResult(bizSelfTestService.getDBTestQuestions(selftestId, openId));
    }

    /**
     * 自测题题目得分
     */
    @RequestMapping(value = "/aiHealthReport/selftestResult", method = { RequestMethod.POST })
    public RetResult getTestQuestionsScore(@RequestBody TestQuestionResultDto testQuestionResultDto){
        return new RetResult().of(CodeEnum.SUCCESS).setResult(bizSelfTestService.getDBTestQuestionsScore(testQuestionResultDto));
    }

    /**
     *  健康量表
     */
    @RequestMapping(value = "/aiHealthReport/selftestList", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getHealthTable(){
        return new RetResult().of(CodeEnum.SUCCESS).setResult(bizSelfTestService.getDBHealthTable());
    }

}
